#include<stdio.h>
int a; 
int b;
int d;
int h;
int n;
int f;
int w;
int i;
int j; 
int z;
int y;
 void shuzi()                
{
  a++; 
}
void zimu ()
{
  b++;	
}
void daimahang()
{
  d++;	
}
void konghang()
{
 h++;	
}
void zhushi()
{
 n++; 	
}
void fuhao()
{
 f++;	
}
void danci()
{
 w++;	
}
void juzi()
{
 i++;	
}
int main()
{
char filename[30],x,k,m[10];
FILE *fp;
while(1)
{
	a=b=d=h=n=f=w=i=z=0;
	m[0]=EOF;
    printf("请输入文件名:\n");
    scanf("%s",filename);
    printf("请输入你要统计部分:\n");
    scanf("%s",m);
    fp=fopen(filename,"r");
    if(fp==NULL)
  {
    printf("未找到文件\n");
  }
  x=fgetc(fp);
  	while(x!=EOF)
  	{
	  	if(x>='0'&&x<='9')
	  	shuzi(); 
	  	else if(x>='a'&&x<='z')
	  	zimu();
	  	else if(x=='\n')
	  	daimahang();
	  	else if(x==' ')
	  	konghang();
	  	else if(x=='.'&x==','&x=='!')
	  	fuhao();
	  	j=0;
	    if(x=='/')
	    {
    		j++;
    	}
    	if(x==' ')
    	danci();
		if(x=='.')
		juzi(); 
    	if((x=fgetc(fp))=='/')
    	j++;
    	if(j==2)
    	zhushi();
  	 }
  	 z=a+b+d+h+n+f;
  	 if(m[0]=='z')
  	 printf("字符: %d\n",z);
  	 if(m[0]=='w')
  	 printf("单词：%d\n",w);
	 if(m[0]=='i')
	 printf("句子：%d\n",i); 
	 if(m[0]=='a')
	 printf("数字：%d\n",a);
	 if(m[0]=='b')
	 printf("字母：%d\n",b);
	 if(m[0]=='d')
	 printf("代码行：%d\n",d);
	 if(m[0]=='h')
	 printf("空行：%d\n",h);
	 if(m[0]=='n')
	 printf("注释：%d\n",n); 
  fclose(fp);
 } 
return 0;
}